<?php
include_once('include/Config.php');
include_once('datos/ReporteSmgDAL.php');

$empresaId = empresaidSMG;

$sql = "Where s.idEmpresa = " . $empresaId;

if (isset($_GET['arrSolicitudes'])) {
		
	$sql .= " and s.numSolicitud in (" . $_GET['arrSolicitudes'] . ")";

}

//echo $sql;exit;

$repo = new ReporteSmgDAL();

$dataArray = $repo->obtenerReporteArrayTxt($sql);
$cantidadFilas = count($dataArray);

if ($cantidadFilas < 1) {
    $dataArray = array();
}


$fileName = "Ventas_SMG_" . date("dmy") . ".txt";

if (file_exists($fileName)) {
    unlink($fileName);
}

//echo "<br>--" . PHP_EOL_CUSTOM . "--<br>";exit;

header('Content-disposition: attachment; filename=' . $fileName);
header('Content-type: text/plain');

foreach ($dataArray as $value) {
   $final = $value; 
   echo $final . PHP_EOL_CUSTOM;
}

?>